// 根据权限控制访问方法
// 定义用户类型
type UserType = {
  name: string,
  isLogin: boolean,
  permissions: string[]
}
// 定义用户
const userZeng: UserType = {
  name: 'zrf',
  isLogin: true,
  permissions: ['store', 'manage']
}
//

const AccessDecoratorFactory = (keys: string[]): MethodDecorator =>
  (...args: any[]) => {
    const [, , descriptor] = args
    const method = descriptor.value

    // 权限验证
    const validate = keys.every(key => {
      // 新特性,要把es5改成Esnext
      return userZeng.permissions.includes(key)
    })
    descriptor.value = () => {
      if (validate && userZeng.isLogin) {
        return method()
      }
      console.log('你暂时无权限');
    }
  }

{
  class Article {
    show() {
      console.log('显示文章');
    }
    @AccessDecoratorFactory(['store', 'manage'])
    store() {
      console.log('保存文章');
    }
  }

  new Article().show()
  new Article().store()

}